package spring.cloud.tasks.tasks_manager.schedule;

import spring.cloud.tasks.common.status.TaskInstanceInfoStatus;

import java.util.Date;

/**
 * 只要实例信息+分片信息注册成功后，该节点则不允许修改。（这个对象用于调度器挂了之后，进行实例对象构建的基础）
 */
public class TaskInstanceBaseInfo {
    private String runType;
    private String stateFullTask = "N";//默认都是无状态的任务(简单分片任务)
    private String taskType;
    private String taskId;

    private String taskInstanceId;
    private String oldTaskInstanceId;//重跑这个值不为空
    private volatile String status = TaskInstanceInfoStatus.$register_task_instance_info_success$;
    private String currentStage;
    private String currentStageStatus;

    private long fireDateTimeVersion;
    private Date nextPreAssignDate;
    private long preAssignTimeStamp;
    private Date nextFireDate;
    private Date timeoutDateTime;//超时时间
    private Date lockDateTime;//lock时间
    private Date clearDateTime;
    //
    private int timeoutMinutes;//超时时间
    private int lockMinutes;//lock时间,相对超时时间的增量
    private int clearMinutes;//相对lock时间的增量
    //
    private String taskProperties;
    private String taskDataRangeRule;
    private String taskItemInfo;
    //
    private String taskLevel;
    //
    /**
     * 注册实例阶段分片信息后,更新该值为true,如果调度器挂了。则需要根据当前实例状态更新是否已经注册了。
     */
    private final boolean registered = false;
    private final int tryCreateInstanceInfoTime = 0;
    //待生成实例信息 待预调度  预调度中 禁用取消 完成任务
    private final String errorInfo = "";
    /**
     * 只要任务实例取消，那么则不进行后续的调度、
     */
    boolean isCancelled = false;


    //
    public void copy(TaskInstanceInfo taskInstanceInfo) {
        this.runType = taskInstanceInfo.getRunType();
        this.stateFullTask = "N";//默认都是无状态的任务(简单分片任务)
        this.taskType = taskInstanceInfo.getTaskType();
        this.taskId = taskInstanceInfo.getTaskId();

        this.taskInstanceId = taskInstanceInfo.getTaskInstanceId();
        this.oldTaskInstanceId = taskInstanceInfo.getOldTaskInstanceId();//重跑这个值不为空
        this.status = taskInstanceInfo.getStatus();
        this.currentStage = taskInstanceInfo.getCurrentStage();
        this.currentStageStatus = taskInstanceInfo.getCurrentStageStatus();

        this.fireDateTimeVersion = taskInstanceInfo.getVersion();
        this.nextPreAssignDate = taskInstanceInfo.getNextPreAssignDate();
        this.preAssignTimeStamp = taskInstanceInfo.getPreAssignTimeStamp();
        this.nextFireDate = taskInstanceInfo.getNextFireDate();
        this.timeoutDateTime = taskInstanceInfo.getTimeoutDateTime();//超时时间
        this.lockDateTime = taskInstanceInfo.getLockDateTime();//lock时间
        this.clearDateTime = taskInstanceInfo.getClearDateTime();
        //
        this.timeoutMinutes = taskInstanceInfo.getTimeoutMinutes();//超时时间
        this.lockMinutes = taskInstanceInfo.getLockMinutes();//lock时间,相对超时时间的增量
        this.clearMinutes = taskInstanceInfo.getClearMinutes();//相对lock时间的增量
        //
        this.taskProperties = taskInstanceInfo.getTaskProperties();
        this.taskDataRangeRule = taskInstanceInfo.getTaskDataRangeRule();
        this.taskItemInfo = taskInstanceInfo.getTaskItemInfo();
        //
        this.taskLevel = taskInstanceInfo.getTaskLevel();
    }
}
